package pages;

import java.util.List;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import utils.BaseAction;

public class HomePage {
	private AndroidDriver<AndroidElement> driver;
	private BaseAction action;
	
	public HomePage(AndroidDriver<AndroidElement> driver) {
		this.driver=driver;
		this.action=new BaseAction(driver);
	}

	//用户名输入框
	public AndroidElement psw_login_tele() {
		return driver.findElementById("com.example.petwithlove:id/psw_login_tele");
	}
	//密码输入框
	public AndroidElement login_password() {
		return driver.findElementById("com.example.petwithlove:id/login_password");
	}
	//登录按钮
	public AndroidElement btn_pswlogin() {
		return driver.findElementById("com.example.petwithlove:id/btn_pswlogin");
	}
	
	//底栏五个按钮
	public List<AndroidElement> ivIcon() {
		return driver.findElementsById("com.example.petwithlove:id/ivIcon");
	}
	//我——编辑资料按钮
	public AndroidElement btn_data() {
		return driver.findElementById("com.example.petwithlove:id/btn_data");
	}
	//我——用户名修改框
	public AndroidElement edt_userName() {
		return driver.findElementById("com.example.petwithlove:id/edt_userName");
	}
	//我——保存个人资料按钮
	public AndroidElement btn_preservation() {
		return driver.findElementById("com.example.petwithlove:id/btn_preservation");
	}
	//我——更换头像按钮
	public AndroidElement btn_changeUserHead() {
		return driver.findElementById("com.example.petwithlove:id/btn_changeUserHead");
	}
	//我——选择图片按钮
	public List<AndroidElement> imageView() {
		return driver.findElementsByClassName("android.widget.ImageView");
	}
	//我——确认选择图片按钮
	public AndroidElement head_select_right() {
		return driver.findElementById("com.android.gallery3d:id/head_select_right");
	}
	//我——地区输入框
	public AndroidElement edt_userAddress() {
		return driver.findElementById("com.example.petwithlove:id/edt_userAddress");
	}
	//我——城市选择确认按钮
	public AndroidElement btnSubmit() {
		return driver.findElementById("com.example.petwithlove:id/btnSubmit");
	}
	//我——详细地址输入框
	public AndroidElement edt_location() {
		return driver.findElementById("com.example.petwithlove:id/edt_location");
	}
	

	//加号——发帖内容框
	public AndroidElement edt_textArea() {
		return driver.findElementById("com.example.petwithlove:id/edt_textArea");
	}
	//加号——发布按钮
	public AndroidElement btn_issuance() {
		return driver.findElementById("com.example.petwithlove:id/btn_issuance");
	}
	
	//宠物寄养按钮
	public AndroidElement foster_care() {
		return driver.findElementById("com.example.petwithlove:id/ib_pet_foster");
	}
	//宠物对比按钮
	public AndroidElement comparison() {
		return driver.findElementById("com.example.petwithlove:id/ib_pet_contrast");
	}
	//添加图片按钮
	public AndroidElement add_picture() {
		return driver.findElementById("com.example.petwithlove:id/ib_selectPicture");
	}
	//选择图片按钮
	public List<AndroidElement> chose_picture() {
		return driver.findElementsById("com.example.petwithlove:id/check_view");
	}
	//使用图片按钮
	public AndroidElement use_picture() {
		return driver.findElementById("com.example.petwithlove:id/button_apply");
	}
	//确认扫描图片按钮
	public AndroidElement confirm_scan_picture() {
		return driver.findElementById("com.example.petwithlove:id/btn_sure");
	}
	//点赞图标
	public AndroidElement iv_thumb() {
		return driver.findElementById("com.example.petwithlove:id/iv_thumb");
	}
	//删除动态
	public AndroidElement btn_delete(){
		return driver.findElementById("com.example.petwithlove:id/btn_delete");
	}

	//救助
	public List<AndroidElement> rescue() {
		return driver.findElementsByClassName("androidx.appcompat.app.ActionBar$Tab");
	}
	//标题
	public AndroidElement bannerTitle() {
		return driver.findElementById("com.example.petwithlove:id/bannerTitle");
	}
	//宠物网搜索框
	public List<AndroidElement> editText() {
		return driver.findElementsByClassName("android.widget.EditText");
	}
	//宠物大全
	public List<AndroidElement> pet_collection() {
		return driver.findElementsByClassName("android.view.View");
	}
	//收藏
	public AndroidElement collection() {
		return driver.findElementByXPath("//android.widget.TextView[@text='收藏']");
	}

	//小宠物知识科普
	public AndroidElement popular_science_of_small_pet_knowledge() {
		return driver.findElementByXPath("//android.widget.TextView[@text='小宠物知识科普']");
	}
	//安哥拉兔
	public AndroidElement angora_rabbit() {
		return driver.findElementByXPath("//android.widget.TextView[@text='安哥拉兔']");
	}
//	//波奇宠物网站搜索框keyword
//	public AndroidElement keyword() {
//		return driver.findElementByXPath("//android.widget.EditText[@text='请输入词条/文章/问题关键字']");
//	}
	//安哥拉兔-问答
	public AndroidElement questions_and_answers() {
		return driver.findElementByXPath("//android.view.View[3]/android.view.View[1]/android.widget.TextView[@text='问答']");
	}
	//我要寻找
	public AndroidElement ib_lost() {
		return driver.findElementById("com.example.petwithlove:id/ib_lost");
	}
	//我要寻找-描述
	public AndroidElement et_rescue_text() {
		return driver.findElementById("com.example.petwithlove:id/et_rescue_text");
	}
	//我要寻找-姓名
	public AndroidElement et_rescue_name() {
		return driver.findElementById("com.example.petwithlove:id/et_rescue_name");
	}
	//我要寻找-联系方式
	public AndroidElement et_rescue_phone() {
		return driver.findElementById("com.example.petwithlove:id/et_rescue_phone");
	}
	//我要寻找-所在位置
	public AndroidElement et_rescue_address() {
		return driver.findElementById("com.example.petwithlove:id/et_rescue_address");
	}
	//我要寻找-选择图片
	public AndroidElement ib_rescue_choose_photo() {
		return driver.findElementById("com.example.petwithlove:id/ib_rescue_choose_photo");
	}
	//我要寻找-选中图片
	public List<AndroidElement> check_view() {
		return driver.findElementsById("com.example.petwithlove:id/check_view");
	}
	//我要寻找-使用
	public AndroidElement button_apply() {
		return driver.findElementById("com.example.petwithlove:id/button_apply");
	}
	//我要寻找-帮助按钮
	public AndroidElement btn_rescue_submit() {
		return driver.findElementById("com.example.petwithlove:id/btn_rescue_submit");
	}
	
	//我要救助
	public AndroidElement ib_rescue() {
		return driver.findElementById("com.example.petwithlove:id/ib_rescue");
	}
	//我要救助-需要帮助
	public AndroidElement rescue_radiobutton_help() {
		return driver.findElementById("com.example.petwithlove:id/rescue_radiobutton_help");
	}
	
	//消息-发送消息的userId 
	public AndroidElement edt_toChatUser() {
		return driver.findElementById("com.example.petwithlove:id/edt_toChatUser");
	}
	//消息-发送按钮
	public AndroidElement btn_chat() {
		return driver.findElementById("com.example.petwithlove:id/btn_chat");
	}
	
	//我-我的寻找
	public AndroidElement my_found() {
		return driver.findElementByXPath("//android.widget.TextView[@text='我的寻找']");
	}
	//宠物网-宠物知识
	public AndroidElement pet_knowledge() {
		return driver.findElementByXPath("//android.widget.TextView[@text='宠物知识']");
	}
	
	//1.登录
	public void login(String context1,String context2) throws InterruptedException {
		action.type(psw_login_tele(), context1);
		action.type(login_password(), context2);
		action.click(btn_pswlogin());
	}
	//仅使用期间允许
	public AndroidElement permission_allow_button() {
		return driver.findElementByXPath("//android.widget.Button[@text='仅使用期间允许']");
	}
	//2.修改用户名
	public void update_username(String context) throws InterruptedException {
		action.click(ivIcon().get(4));
		action.click(permission_allow_button());
		action.click(btn_data());
		action.setValue(edt_userName(),context);
		action.click(btn_preservation());
	}
	//允许访问照片
	public AndroidElement allow_picture() {
		return driver.findElementByXPath("//android.widget.Button[@text='允许']");
	}
	//3.更换用户名头像
	public void update_username_picture() throws InterruptedException {
		action.click(ivIcon().get(4));
		action.click(permission_allow_button());
		action.click(btn_data());
		action.click(btn_changeUserHead());
		action.click(allow_picture());
		action.click(imageView().get(1));
		action.click(head_select_right());
		action.click(btn_preservation());
	}
	//4.发帖
	public void post(String context) throws InterruptedException {
		action.click(ivIcon().get(2));
		action.click(permission_allow_button());
		action.type(edt_textArea(), context);
		action.click(btn_issuance());
	}
	//5.宠物寄养
	public void pet_foster_care() throws InterruptedException {
		action.click(ivIcon().get(0));
		action.click(foster_care());
	}
	//6.添加地址
	public void add_address(String context) throws InterruptedException {
		action.click(ivIcon().get(4));
		action.click(permission_allow_button());
		action.click(btn_data());
		action.click(edt_userAddress());
		action.click(btnSubmit());
		action.type(edt_location(), context);
		action.click(btn_preservation());
	}
	//7.宠物对比
	public void pet_comparison() throws InterruptedException {
		action.click(ivIcon().get(0));
		action.click(comparison());
		action.click(add_picture());
		action.click(permission_allow_button());
		action.click(allow_picture());
		action.click(chose_picture().get(1));
		action.click(use_picture());
		action.click(confirm_scan_picture());
	}
	//8.点赞动态 我-点赞
	public void like_dynamic() throws InterruptedException {
		action.click(ivIcon().get(4));
		action.click(permission_allow_button());
		action.click(iv_thumb());
	}
	//9.删除动态 我-删除
	public void delete_dynamic() throws InterruptedException {
		action.click(ivIcon().get(4));
		action.click(permission_allow_button());
		action.click(btn_delete());
	}
	//10.查看救助贴 社区-求助
	public void view_help_post() throws InterruptedException {
		action.click(ivIcon().get(1));
		action.click(rescue().get(1));
	}
	//11.在宠物网搜索小狗 点击主页大图-搜索框点击，输入小狗
	public void view_pet_news() throws InterruptedException {
		action.click(ivIcon().get(0));
		action.click(bannerTitle());
	}
	//12.查看宠物大全 点击主页大图-点击宠物大全
	public void view_pet_collection() throws InterruptedException {
		action.click(ivIcon().get(0));
		action.click(bannerTitle());
		action.click(pet_collection().get(3));
	}
	//13.查看我的收藏 我-收藏
	public void view_my_collection() throws InterruptedException {
		action.click(ivIcon().get(4));
		action.click(permission_allow_button());
		action.click(collection());
	}
	//相机
	public AndroidElement btn_select_photo() {
		return driver.findElementById("com.example.petwithlove:id/btn_select_photo");
	}
	//拍一张
	public AndroidElement hint() {
		return driver.findElementById("com.example.petwithlove:id/hint");
	}
	//点击拍照按钮
	public AndroidElement shutter_button() {
		return driver.findElementById("com.huawei.camera:id/shutter_button");
	}
	//确认选择该图片
	public AndroidElement done_button() {
		return driver.findElementById("com.huawei.camera:id/done_button");
	}
	//14.发送一条带有本机直接拍摄的照片的帖子 加号-输入发帖内容-点击相机图案-点击拍一张-点击拍照-点击对号按钮-点击发布按钮
	public void post_and_take_a_picture(String context) throws InterruptedException {
		action.click(ivIcon().get(2));
		action.click(permission_allow_button());
		action.type(edt_textArea(), context);
		action.click(btn_select_photo());
		action.click(allow_picture());
		action.click(btn_select_photo());
		action.click(hint());
		action.click(shutter_button());
		action.click(done_button());
		action.click(btn_issuance());
	}
	
	//15.寻找宠物 救助-我要寻找-描述，姓名，联系方式，所在位置，图片-点击帮助按钮
	public void search_pet(String context1,String context2,String context3,String context4) throws InterruptedException {
		action.click(ivIcon().get(0));
		action.click(ib_lost());
		action.type(et_rescue_text(),context1);
		action.type(et_rescue_name(),context2);
		action.type(et_rescue_phone(), context3);
		action.type(et_rescue_address(), context4);
		action.click(ib_rescue_choose_photo());
		action.click(permission_allow_button());
		action.click(allow_picture());
		action.click(ib_rescue_choose_photo());
		action.click(check_view().get(1));
		action.click(button_apply());
		action.click(btn_rescue_submit());
	}
	//16.向momo发送消息 消息-输入userId-点击发送
	public void send_message(String context) throws InterruptedException {
		action.click(ivIcon().get(3));
		action.click(permission_allow_button());
		action.type(edt_toChatUser(), context);
		action.click(btn_chat());
	}
	//17.查看我的寻找 我-的寻找
	public void view_my_search() throws InterruptedException {
		action.click(ivIcon().get(4));
		action.click(permission_allow_button());
		action.click(my_found());
	}
	//18.我要救助  救助-我要救助-描述，姓名，联系方式，所在位置，图片，需要帮助-点击帮助按钮
	public void need_help(String context1,String context2,String context3,String context4) throws InterruptedException {
		action.click(ivIcon().get(0));
		action.click(ib_rescue());
		action.type(et_rescue_text(),context1);
		action.type(et_rescue_name(),context2);
		action.type(et_rescue_phone(), context3);
		action.type(et_rescue_address(), context4);
		action.click(ib_rescue_choose_photo());
		action.click(permission_allow_button());
		action.click(allow_picture());
		action.click(ib_rescue_choose_photo());
		action.click(check_view().get(1));
		action.click(button_apply());
		action.click(rescue_radiobutton_help());
		action.click(btn_rescue_submit());
	}
	//19.在宠物网查看宠物知识
	public void view_pet_knowledge() throws InterruptedException {
		action.click(ivIcon().get(0));
		action.click(bannerTitle());
		action.click(pet_knowledge());
	}
	//20.登录-错误的密码123
	public void login_wrong(String context1,String context2) throws InterruptedException {
		action.type(psw_login_tele(), context1);
		action.type(login_password(), context2);
		action.click(btn_pswlogin());
	}
	
}
